package com.aaa.controller;

import com.aaa.service.L_dataqueryService;
import com.aaa.util.EmpUtil;
import com.aaa.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;
/*
* 资料申报
*
* */
@Controller
@RequestMapping("/dataquery")
public class L_dataqueryController {
    @Autowired
    L_dataqueryService service;
    @Value("${upload.path}")
    private String filePath;
    private String title;
    private String fileurl;
    private String filename;

    @RequestMapping("/main")
    public String main(){
        return "Declarationmanagement/rightmain";
    }

    //资料申报//no  右侧信息界面显示
    @RequestMapping("/dataquery")
    public  String aa(){
        return "Declarationmanagement/Datadeclaration";
    }
    //资料申报右侧主界面
   @RequestMapping("/rightmain2")
   public String aaa(String title){
        this.title=title;
       return "Declarationmanagement/rightmain2";
   }

   //主界面上部分显示
   @RequestMapping("/getSBXM")
   @ResponseBody
   public Object getSBXM(){
        //model.addAttribute("list",service.getSBXM(title));
       System.out.println(title);
       return  service.getSBXM(title);
   }


//显示rightmain2右侧树一级菜单
    @RequestMapping("/treelist")
    @ResponseBody
    public Object yiji(@RequestBody Map map){
        return  service.getYiji(map);
    }

//资料上传方法
    @RequestMapping("/upload")
    @ResponseBody
    public Object upload(@RequestParam("file") MultipartFile file){
        String upFile = null;
        if(file!=null&&!file.isEmpty()){
            upFile = FileUtil.uploadFile(filePath, file);//获取文件路径
            String fileName=file.getOriginalFilename();//获取上传文件的名字
            fileurl=upFile;
            filename=fileName;
        }
        return upFile;
    }
    //单位申报资料
    @RequestMapping("/insertdata")
    @ResponseBody
    public void SB(@RequestBody Map map) {
        System.out.println(fileurl+"        文件路径");
        System.out.println(filename+"      文件名");
        System.out.println(map.get("id")+"      testid");
        map.put("title",title);
        map.put("filepath",fileurl);
        map.put("filename",filename);
        service.insertdata(map);
    }

    //查询单位申报是否重复
    @RequestMapping("/chachong")
    @ResponseBody
    public Object chachong(@RequestBody Map map){
        map.put("danwei", EmpUtil.getMessage().getName());
        Map map1=new HashMap();
        map1.put("rep",service.rep(map));
        return map1;
    }
}
